<template>
	<view class="main">
		<view class="card">
			<!-- <view class="card-tit flex align"><text></text>个人信息</view> -->
			<view class="input-item flex align">
				<view>姓名</view>
				<input placeholder="输入姓名" v-model="info.realname" />
			</view>
			<view class="input-item flex align" @click="toShow()">
				<view>性别</view>
				<view :style="info.sex==''?'color:grey':''">{{info.sex==''?'点击选择':info.sex_text}}</view>
				<!-- <input placeholder="输入法人" v-model="info.sex_text" /> -->
			</view>
			<view class="input-item flex align">
				<view>联系电话</view>
				<input placeholder="输入联系电话" v-model="info.mobile" />
			</view>
			<view class="input-item flex align">
				<view>身份证号</view>
				<input placeholder="输入联系电话" v-model="info.id_card" />
			</view>
			<!-- <view class="input-item flex align" v-if="info.in_region_text!=''">
				<view>流入地</view>
				<view class="address" style="width: 500rpx;">
					<uni-data-picker v-model="info.in_region" :clear-icon="false" :localdata="items" popup-title="请所在区域"
						@change="onchange"></uni-data-picker>
				</view>
			</view> -->
			<view class="input-item flex align">
				<view>从事行业</view>
				<input placeholder="输入工作岗位" v-model="info.job" />
			</view>
			<view class="input-item flex align" v-if="info.in_region_text!=''">
				<view>流入地</view>
				<view style="background: gainsboro;padding: 10rpx;width: 70%;">{{info.in_region_text}}</view>
			</view>
			<view class="input-item flex align" v-if="info.in_organization_text!=''">
				<view>流入党组织</view>
				<view style="background: gainsboro;padding: 10rpx;width: 70%;">{{info.in_organization_text}}</view>
			</view>
			<view class="input-item flex align" v-if="info.out_region_text!=''">
				<view>流出地</view>
				<view style="background: gainsboro;padding: 10rpx;width: 70%;">{{info.out_region_text}}</view>
			</view>
			<view class="input-item flex align" v-if="info.out_organization_text!=''">
				<view>流出党组织</view>
				<view style="background: gainsboro;padding: 10rpx;width: 70%;">{{info.out_organization_text}}</view>
			</view>
		
		</view>
		<view class="resign-btn" @click="toResign()">保存</view>
	<u-picker :show="show" :columns="columns" @confirm="confirm" @cancel="show = false"></u-picker>
	</view>
</template>

<script>
	import {
		userDetail,
		regionLists,
		editInfo
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				info: '',
				items:[],
				columns: [
					['男', '女']
				],
				show: false,
			};
		},
		onLoad() {
			this.getDetail()
			// this.getRegion()
		},
		methods:{
			toShow(){
				this.show = true
				console.log(666)
			},
			async getRegion() {
				const result = await regionLists()
				result.data.forEach(item => {
					item.text = item.name
					item.value = item.id
					item.children.forEach(item2 => {
						item2.text = item2.name
						item2.value = item2.id
						if (item2.children.length > 0) {
							item2.children.forEach(item3 => {
								item3.text = item3.name
								item3.value = item3.id
							})
						}
					})
				})
				this.items = result.data
			},
			onchange(e) {
				const value = e.detail.value
				console.log(value)
				let arr = []
				value.forEach(item => {
					arr.push(item.value)
				})
				this.info.out_region = arr
			},
			confirm(e) {
				this.info.sex_text = e.value[0]
				if(e.value[0]=='男'){
					this.info.sex = 1
				}else{
					this.info.sex = 2
				}
				this.show = false
			},
			async getDetail() {
				const result = await userDetail()
				if (result.code == 1) {
					this.info = result.data
				} else {
					uni.showToast({
						title: result.msg,
						icon: 'error'
					});
				}
			},
			// 入驻
			async toResign() {
				let obj = {
					realname: this.info.realname,
					sex: this.info.sex,
					mobile: this.info.mobile,
					job: this.info.job,
					id_card: this.info.id_card,
				}
				if (obj.realname == '') {
					uni.showToast({
						title: '请输入姓名',
						icon: 'error'
					})
					return false
				}
				if (obj.sex == '') {
					uni.showToast({
						title: '请选择性别',
						icon: 'error'
					})
					return false
				}
				if (obj.mobile == '') {
					uni.showToast({
						title: '请输入联系电话',
						icon: 'error'
					})
					return false
				}
				const result = await editInfo(obj)
				if (result.code == 1) {
					uni.showToast({
						title: result.msg,
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 500)
				} else {
					uni.showToast({
						title: result.msg,
						icon: 'error'
					})
				}
			},
		},
		
	}
</script>

<style lang="scss" scoped>
.main {
		margin: 24rpx;
		padding-bottom: 100rpx;

		.card {
			border-radius: 12rpx;
			box-shadow: 1rpx 1rpx 5rpx 1rpx gainsboro;
			padding: 0rpx 24rpx 20rpx;
			background: white;
			margin-bottom: 30rpx;

			.loadUp {
				background: #D9D9D9;
				border-radius: 12rpx;
				width: fit-content;
				padding: 43rpx;
				margin-top: 20rpx;
			}

			.logo {
				image {
					width: 150rpx;
					height: 150rpx;
				}
			}

			.card-tit {
				font-size: 32rpx;
				font-weight: bold;

				text {
					background: #FF6543;
					display: block;
					width: 5rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
			}

			.input-item {
				padding: 19rpx 0;
				border-bottom: solid 1rpx #D9D9D9;
				font-size: 28rpx;

				view {
					width: 30%;
				}
				.address{
					view{
						width: 100%;
					}
				}
			}
		}

		.resign-btn {
			background: #C23015;
			border-radius: 32rpx;
			font-size: 26rpx;
			font-weight: bold;
			color: white;
			padding: 17rpx 0;
			margin: 80rpx auto;
			text-align: center;
		}
	}
</style>
